package com.guigu.serviceorder.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.common_util.pojo.utils.Result;
import com.guigu.serviceorder.entity.TbOrderLog;
import com.guigu.serviceorder.mapper.TbOrderLogMapper;
import com.guigu.serviceorder.service.ITbOrderLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2020-07-08
 */
@Service
public class TbOrderLogServiceImpl extends ServiceImpl<TbOrderLogMapper, TbOrderLog> implements ITbOrderLogService {


    @Override
    public Result findPage(Map<String, Object> searchMap, Integer page, Integer size) {
        QueryWrapper<TbOrderLog> wrapper = createExample(searchMap);
        //创建page对象
        Page<TbOrderLog> pageTbOrderLog= new Page<>(page,size);
        baseMapper.selectPage(pageTbOrderLog,null);
        if (pageTbOrderLog.getRecords() == null && pageTbOrderLog.getTotal() == 0){
            return Result.error();
        }
        return Result.ok().data("rows",pageTbOrderLog.getRecords()).data("total",pageTbOrderLog.getTotal());
    }

    // 根据查询条件封装模块对象
    private QueryWrapper<TbOrderLog> createExample(Map<String, Object> searchMap) {
        QueryWrapper<TbOrderLog> wrapper = new QueryWrapper<>();
        if(searchMap!=null) {
            if(searchMap.get("id")!=null)
                wrapper.eq("id",searchMap.get("id"));
            if(searchMap.get("operater")!=null && !"".equals(searchMap.get("operater")))
                wrapper.like("title",searchMap.get("operater"));
        }

        return wrapper;
    }
}
